<html>
	<title>php+jquery+ajax+json简单小例子</title>
	
<head>
<meta charset="utf-8"/>
<script type="text/javascript" src="../js/jquery-1.11.3.min.js"></script>
<script type="text/javascript">  
	$(function() { 
	// $(document).ready(function(){ 
		$("#subbtn").click(function() {  
			var params = $("input").serialize();  //name = ..&password=..
			// var params = $("input").val();  
			// var params = {
			// 	"name" : "s",
			// 	"password" : "fuck"
			// }
			// var params = {
			// 	"name" : $("#name").val(),
			// 	"password" : $("#password").val()
			// }
			var url = "test.php";  
			$.ajax({  
				type: "POST",  
				url: url,  
				dataType: "json",  
				data: params,  
				success: function(msg){  
					var backdata = "您提交的姓名为：" + typeof(msg) +  "<br /> 您提交的密码为：" + msg.name; 
					// var backdata = "<a href='#'>haha</a>" 
							// var backdata = typeof(msg);  //object
							// var backdata =Object.getOwnPropertyNames(msg); //name password
							// location.href = "./index.html";
							$("#backdata").html(backdata);  
							$("#backdata").css({color: "green"});  
						}  
			}); 
			// $.ajax({  
			// 	type: "GET",  
			// 	url: url,  
			// 	dataType: "json",   
			// 	success: function(msg){  
			// 		var backdata = "您提交的姓名为：" + msg.name +  "<br /> 您提交的密码为：" + msg.password; 
			// 				$("#backdata").html(backdata);  
			// 				$("#backdata").css({color: "green"});  
			// 			}  
			// });   
		});  
	});    
</script>
</head>
<body>
	<p>
		<label for="name">姓名：</label>
		<input id="name" name="name"  type="text" />
	</p>

	<p>
		<label for="password">密码：</label>
		<input id="password" name="password"  type="password" />
	</p>
	<span id="backdata"></span>
	<p>
		<input id="subbtn" type="button" value="提交数据" />
	</p>
</body>
</html>
